package com.txl.web.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.txl.domain.ContactGroupBean;
import com.txl.service.ContactGroupService;
import com.txl.utils.WebUtils;

public class EditContactGroupServlet extends HttpServlet {

	ContactGroupService service = new ContactGroupService();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String id = request.getParameter("id");
		ContactGroupBean bean = service.findContactGroup(id);
		request.setAttribute("bean", bean);
		request.getRequestDispatcher("/page/editgroup.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		try{
			ContactGroupBean cg = WebUtils.request2Bean(request, ContactGroupBean.class);
			service.updateContactGroup(cg);
			request.setAttribute("message", "更新成功！！");
		}catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("message", "更新失败！！");
		}
		request.getRequestDispatcher("/message.jsp").forward(request, response);
	}

}
